﻿package {
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.utils.getTimer;

	import lu.kyle.IntBlock;

	public class IntBlockTest extends Sprite {
		public function IntBlockTest() {
			init();
		}
		private function init():void {
			stage.addEventListener(MouseEvent.CLICK, onClickStage);
		}
		private function onClickStage(evt:MouseEvent):void {
			var arr:Array = new Array(64);
			var i:int, j:int;
			var num:int;
			var line:String;
			var pos:int = 0;
			for (i = 1; i <= 8; ++i) {
				line = "";
				for (j = 8; j >= 1; --j) {
					num = i * j;
					if (num < 10) line += '0';
					line += num.toString() + ", ";

					arr[pos++] = num;
				}
				trace(line);
			}
			trace('--------------------------------');

			var block:IntBlock = IntBlock.create8_8(arr);
			var row:IntBlock = block;
			var col:IntBlock = block;
			for (i = 1; i <= 8; ++i) {
				line = "";
				for (j = 1; j <= 8; ++j) {
					num = row.data;
					if (num < 10) line += '0';
					line += num.toString() + ", ";

					row = row.down;
				}
				trace(line);
				col = col.next;
				row = col;
			}
			trace('--------------------------------');

			const cnt:int = 1000000;
			var tstart:int = getTimer();
			i = cnt;
			while (--i != 0) {
				j = 64;
				while (--j != 0) num = arr[j];
			}
			trace(getTimer() - tstart);
			tstart = getTimer();
			i = cnt;
			while (--i != 0) {
				row = block;
				j = 64;
				while (--j > -1) {
					num = row.data;
					row = row.next;
				}
			}
			trace(getTimer() - tstart);
		}
	}
}
